package examples;
import java.util.Vector;

import trees.MetricTree;
import trees.Pair;


import utils.Metrics;
import java.util.Collections;
import java.util.Comparator;
public class BuildMetricTree {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) {
		MetricTree<String> tree = new MetricTree<String>(new functors.BinaryFunctor<String,String,Integer>() {

			@Override
			public Integer fn(String x, String y) {
				return Metrics.getLevenshteinDistance(x, y);
			}
			
		});
		
		String[] dict = {"abyss","almond","clump", "computer", "nook", "crook", "book", "took", "cookie",
						 "complex",
				
						 "cubic","cuba","adopt", "abused", "chronic" ,"abutted", "cube","clown","admix","almsman"};
		for (int i = 0; i < dict.length; ++i) {
			tree.add(dict[i]);
		}
		
		tree.printObject(System.out);
		int threshold = 3;
		
		Vector<Pair<Integer, String>> results = tree.find("comptr", threshold);
		
		Collections.sort(results, new Comparator<Pair<Integer, String>>() {
			public int compare(Pair<Integer, String> o1, Pair<Integer, String>o2) {
				if (o1 == null && o2 == null) {
					return 0;
				}
				if (o1 == null) {
					return -1;
				}
				else if (o2 == null) {
					return 1;
				}
				else if (o1.getFirst() < o2.getFirst()) {
					return -1;
				}
				else if (o1.getFirst() == o2.getFirst()) {
					return 0;
				}
				else if (o1.getFirst() > o2.getFirst()) {
					return 1;
				}
				return 0;
			}

		

			
		});
		
		System.out.println(results);
	}
	
	
	


}
